package com.ruoyi.common.core.utils;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

public class LocalDateTimeUtils {
    private static final String LOCAL_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

    public static LocalDateTime now() {
        return LocalDateTime.now();
    }

    public static String format(LocalDateTime date) {
        DateTimeFormatter dft = DateTimeFormatter.ofPattern(LOCAL_DATE_TIME_PATTERN);
        return dft.format(date);
    }


    /**
     * 获取指定日期的开始时刻
     */
    public static LocalDateTime getDayMin(LocalDate date) {
        return LocalDateTime.of(date, LocalTime.MIN);
    }

    /**
     * 获取指定日期的结束时刻
     */
    public static LocalDateTime getDayMax(LocalDate date) {
        return LocalDateTime.of(date, LocalTime.MAX);
    }

    /**
     * 获取指定月份的开始时刻
     */
    public static LocalDateTime getMonthMin(Integer year, Integer month) {
        return getDayMin(LocalDate.of(year, month, 1));
    }

    /**
     * 获取指定月份的结束时刻
     */
    public static LocalDateTime getMonthMax(Integer year, Integer month) {
        LocalDate lastDay = LocalDate.of(year, month, 1).with(TemporalAdjusters.lastDayOfMonth());
        return getDayMax(lastDay);
    }
}
